home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / qex / qexcvsd / mxitest.c < prev    next >
Text File  |  1990-07-27  |  2KB  |  121 lines

  1. /* MX-COM MX709 CODEC board test program (interrupt version) */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <alloc.h>
  6. #include <bios.h>
  7. #include <ctype.h>
  8. #include <dos.h>
  9.  
  10. #include "mxcom.h"
  11.  
  12. #define IRQ        5
  13.  
  14. char *
  15. prompt(char *pmt)
  16. {
  17.     static char reply[120];
  18.  
  19.     printf("%s", pmt);
  20.     gets(reply);
  21.     return reply;
  22. }
  23.  
  24. static int over = 0;
  25. static char *buf;
  26. static unsigned n;
  27. static int cnt;
  28. static long intc;
  29.  
  30. void interrupt
  31. service()
  32. {
  33.     unsigned char stat;
  34.  
  35.     intc++;
  36.     stat = inportb(MX_STAT);
  37.     if (cnt < n && (stat & 0x12))
  38.         outportb(MX_DEC, buf[cnt++]);
  39.     if (stat & 0x10)
  40.         over++;
  41.     stat = inportb(MX_STAT);
  42.     if (stat & 9)
  43.         inportb(MX_ENC);
  44.     if (stat & 0x24)
  45.         inportb(MX_PWR);
  46.     outportb(0x20, 0x20);
  47. }
  48.  
  49. int
  50. main()
  51. {
  52.     char *p;
  53.     FILE *fil;
  54.     int i, pgm;
  55.     void interrupt (*oldv)();
  56.  
  57.     while (1)
  58.     {
  59.         p = prompt("File to play: ");
  60.         if ((fil = fopen(p, "rb")) == NULL)
  61.         {
  62.             perror(p);
  63.             continue;
  64.         }
  65.         if (fseek(fil, 0L, SEEK_END))
  66.         {
  67.             perror(p);
  68.             continue;
  69.         }
  70.         n = (int) ftell(fil) - sizeof pgm;
  71.         if ((buf = malloc(n)) == NULL)
  72.         {
  73.             puts("Insufficient memory");
  74.             fclose(fil);
  75.             continue;
  76.         }
  77.         fseek(fil, 0L, SEEK_SET);
  78.         fread(&pgm, sizeof i, 1, fil);
  79.         if (pgm == -1)
  80.         {
  81.             puts("CODEC programming bits not available");
  82.             pgm = 0;
  83.         }
  84.         if (fread(buf, 1, n, fil) != n)
  85.         {
  86.             perror(p);
  87.             free(buf);
  88.             fclose(fil);
  89.             continue;
  90.         }
  91.         fclose(fil);
  92.         printf("%u bytes loaded.\n", n);
  93.         while (1)
  94.         {
  95.             puts("Hit any key to play, ESC to reload...");
  96.             if ((bioskey(0) & 0xff) == 0x1b)
  97.                 break;
  98.             outportb(MX_A, pgm+3);
  99.             outportb(MX_B, 0x38);
  100.             cnt = 0;
  101.             over = 0;
  102.             inportb(MX_STAT);
  103.             oldv = getvect(IRQ+8);
  104.             setvect(IRQ+8, service);
  105.             disable();
  106.             outportb(0x21, inportb(0x21) & ~(1 << IRQ));
  107.             outportb(0x20, 0x20);
  108.             enable();
  109.             outportb(MX_ENC, buf[cnt++]);
  110.             while (cnt < n && (bioskey(1) & 0xff) != 0x1b)
  111.                 ;
  112.             disable();
  113.             outportb(0x21, inportb(0x21) | (1 << IRQ));
  114.             enable();
  115.             setvect(IRQ+8, oldv);
  116.             if (bioskey(1) != 0)
  117.                 bioskey(0);
  118.             printf("%ld interrupts, %d decode overspills\n", intc, over);
  119.         }
  120.     }
  121. }